package com.cc.openeye.dynamic.kuikly.listObserableStatusChange

import com.tencent.kuikly.core.pager.Pager
import com.tencent.kuikly.core.annotations.Page
import com.tencent.kuikly.core.base.Color
import com.tencent.kuikly.core.base.ViewBuilder
import com.tencent.kuikly.core.directives.vfor
import com.tencent.kuikly.core.directives.vforIndex
import com.tencent.kuikly.core.nvi.serialization.json.JSONArray
import com.tencent.kuikly.core.reactive.handler.observableList
import com.tencent.kuikly.core.views.List
import com.tencent.kuikly.core.views.Text
import com.tencent.kuikly.core.views.View
import kotlinx.serialization.json.JsonArray

@Page("ObserveListPage")
internal class ObserveListPage : Pager() {

    private val dataList by observableList<ObserveEntity>()

    override fun created() {
        super.created()
        for (i in 0..10) {
            dataList.add(ObserveEntity().apply {
                params1 = "Observe:$i"
            })
        }
    }

    override fun body(): ViewBuilder {
        val ctx = this
        JSONArray()
        return {
            View {
                attr {
                    flex(1f)
                    backgroundColor(Color.RED)
                }

                List {
                    attr {
                        flex(1f)
                    }



                    vforIndex({ctx.dataList}) { item, index, count ->
                        View {
                            attr {
                                height(50f)
                                justifyContentCenter()
                                alignItemsCenter()
                                backgroundColor(Color.YELLOW)
                            }

                            Text {
                                attr {
                                    value(item.params1)
                                }

                                event {
                                    click {
                                        item.params1 = "dsadsa"
                                        ctx.dataList[index] = ctx.dataList[index]

                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
    }
}